﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChatForum.Business.Contract;
using ChatForum.Business.Logic;
using ChatForum.Business.Entity;

namespace ChatForum.Application.Service
{
    public class ForumService : IForumService
    {
        public ForumService(IRepository repository)
            :base(repository)
        {
        }
        public override void CreateCategory(Category category)
        {
            if (category == null)
                throw new ArgumentNullException("category");
            ForumLogic.CreateCategory(category, _repository);
        }
        public override void CreatePost(Post post)
        {
            if (post == null)
                throw new ArgumentNullException("post");
            ForumLogic.CreatePost(post, _repository);
        }
		public override IEnumerable<Category> GetAllCategory()
		{
			return ForumLogic.GetAllCategory(_repository);
		}

		public override IEnumerable<Post> GetPostbyCategory(Guid categoryId, bool includeChildren)
		{
			if (categoryId == null)
				throw new ArgumentNullException("categoryId");
			return ForumLogic.GetPostbyCategory(categoryId, includeChildren, _repository);
		}
		public override IEnumerable<Post> GetPostbyCreator(string userId, bool includeChildren)
		{
			if (string.IsNullOrWhiteSpace(userId))
				throw new ArgumentNullException("userId");
			return ForumLogic.GetPostbyCreator(userId, includeChildren, _repository);
		}
		public override IEnumerable<Post> GetPostbyParentPost(Guid parentPostid, bool includeChildren)
		{
			if (parentPostid == null)
				throw new ArgumentNullException("parentPostid");
			return ForumLogic.GetPostbyParentPost(parentPostid, includeChildren, _repository);
		}

		public override Category GetCategoryById(Guid catId)
		{
			return ForumLogic.GetCategoryById(catId, _repository);
		}

        public override Post GetPostById(Guid postId)
        {
            return ForumLogic.GetPostById(postId, _repository);
        }
		public override IEnumerable<Post> GetThread(Guid postId)
        {
            return ForumLogic.GetThread(_repository, postId);
        }

		public override void ModifyCategory(Category category)
		{
			if (category == null)
				throw new ArgumentNullException("category");
			ForumLogic.ModifyCategory(category, _repository);
		}
	}
}
